package com.ffe.flower.engine.component;

import java.util.List;

import com.ffe.flower.engine.dto.FlowCriteriaQuery;
import com.ffe.flower.engine.service.IFlowInfoService;
import com.ffe.flower.engine.util.ApplicationContextHelper;
import com.ffe.flower.engine.wrapper.FlowWrapper;

public final class FlowEngine {

  private static IFlowInfoService flowInfoService;

  static {
    try {
      flowInfoService = ApplicationContextHelper.getBean(IFlowInfoService.class);
    } catch (NullPointerException e) {
      // ignore
    }
  }

  public static FlowInstance createInstance(String processId) {
    return ApplicationContextHelper.getApplicationContext().getBean(FlowInstance.class, processId);
  }

  public static FlowInstance createInstance(Integer flowId) {
    return ApplicationContextHelper.getApplicationContext().getBean(FlowInstance.class, flowId);
  }

  public static List<FlowWrapper> query(FlowCriteriaQuery query) {
    return flowInfoService.query(query);
  }

  public static long count(FlowCriteriaQuery query) {
    return flowInfoService.count(query);
  }

}
